'----------------------------------------------
' Name: Ali Karbassi & Mike Raasch
' Date: April 10, 2007
' Description: Project 6
'              Class Comment
'----------------------------------------------
Public Class Comment
	Implements IQuestion

	' Private fields
	Private _index As Integer
   Private _mode As QuestionMode

   ''' <summary>
   ''' The height of the control
   ''' </summary>
   ''' <value></value>
   ''' <returns></returns>
   ''' <remarks></remarks>
   Private Overloads ReadOnly Property height() As Integer Implements IQuestion.height
      Get
         Return Me.ClientSize.Height
      End Get
   End Property

   ''' <summary>
   ''' The width of the control
   ''' </summary>
   ''' <value></value>
   ''' <returns></returns>
   ''' <remarks></remarks>
   Private Overloads ReadOnly Property width() As Integer Implements IQuestion.width
      Get
         Return Me.ClientSize.Width
      End Get
   End Property

   ''' <summary>
   ''' Sets or Reads the question index, which can be stored as the Text of lblIndex.
   ''' </summary>
   ''' <value></value>
   ''' <returns></returns>
   ''' <remarks></remarks>
   Private Overloads Property Index() As Integer Implements IQuestion.Index
      Get
         Return _index
      End Get
      Set(ByVal value As Integer)
         _index = value
      End Set
   End Property

   ''' <summary>
   ''' Use private methods to implement interface
   ''' </summary>
   ''' <remarks></remarks>
	Private Event Changed() Implements IQuestion.Changed

   ''' <summary>
   ''' Removes the question from theForm and then decreases the height of theForm by the height of the 
   ''' control.
   ''' </summary>
   ''' <param name="theForm"></param>
   ''' <remarks></remarks>
   Private Sub Remove(ByVal theForm As System.Windows.Forms.Form) Implements IQuestion.Remove

      theForm.Controls.Remove(Me)
      theForm.Height -= Me.height

   End Sub

   ''' <summary>
   ''' Checks if the question is completed and throws an exception if not completed.
   ''' </summary>
   ''' <remarks></remarks>
   Private Sub Save() Implements IQuestion.Save

      If txtQuestion.Text.Trim.Length <= 0 Then
         Throw New Exception("No question is entered.")
      ElseIf lblIndex.Text.Trim.Length <= 0 Then
         Throw New Exception("No index is entered.")
      End If

   End Sub

   ''' <summary>
   ''' Returns 1 if answer is not null string, 0 otherwise.
   ''' </summary>
   ''' <returns></returns>
   ''' <remarks>Apparently in VB, True is -1 and False is 0, not True: 1, False:0</remarks>
   Private Function Score() As Integer Implements IQuestion.Score

      Return Math.Abs(CType(txtComment.Text.Trim.Length > 0, Integer))

   End Function

   ''' <summary>
   ''' Displays a question at point Pos of theForm and then increases the height of theForm by the height of 
   ''' the control.
   ''' 
   ''' When theMode is Creating
   '''    TextBox for the question should be Read/Write
   '''    Key should be displayed
   '''    Choice textboxes of MultiCHoice class should be Read/Write
   '''    txtComment of Comment class should be ReadOnly
   ''' 
   ''' When theMode is Taking
   '''    TextBox for the question should be ReadOnly
   '''    Key should NOT be displayed
   '''    Choice textboxes for MultiCHoice class should be ReadOnly
   '''    txtComment for Comment class should be Read/Write
   ''' 
   ''' Set a private field _mode to theMode
   ''' </summary>
   ''' <param name="Pos"></param>
   ''' <param name="theForm"></param>
   ''' <param name="theMode"></param>
   ''' <remarks></remarks>
   Private Sub Display(ByVal Pos As System.Drawing.Point, ByVal theForm As System.Windows.Forms.Form, _
               ByVal theMode As QuestionMode) Implements IQuestion.Display

      theForm.Controls.Add(Me)
      Me.Location = Pos
      theForm.Height += Me.height

      If theMode = QuestionMode.Creating Then
         txtQuestion.ReadOnly = False
      Else
         txtQuestion.ReadOnly = True
         txtQuestion.BackColor = Color.White
      End If

      _mode = theMode
      txtQuestion.Focus()

      lblIndex.Text = _index & "."

   End Sub

End Class
